package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo10 {
    public static void main(String[] args) {
        try( Connection connection = DBUtil.getConnection();) {
            connection.setAutoCommit(false);
            String sql = "DELETE FROM user WHERE id = ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setInt(1,2);
            int num = ps.executeUpdate();
            System.out.println(num>0?"删除成功！":"删除失败！");
            connection.commit();
            System.out.println("事务提交了，删除算数！");
//            connection.rollback();
//            System.out.println("事务回滚了，删除不算数！");

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
